package com.vehiclemanagement.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;

/**
 * 驾驶员信息实体类
 */
@Data
@TableName("driver")
@ApiModel(value = "Driver", description = "驾驶员信息")
public class Driver implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    /**
     * 驾驶员ID
     */
    @ApiModelProperty(value = "驾驶员ID", example = "1", required = false, position = 1)
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;
    
    /**
     * 姓名
     */
    @ApiModelProperty(value = "姓名", example = "张三", required = true, position = 2)
    private String name;
    
    /**
     * 部门
     */
    @ApiModelProperty(value = "部门", example = "运输部", required = true, position = 3)
    private String department;
    
    /**
     * 性别
     */
    @ApiModelProperty(value = "性别", example = "男", allowableValues = "男,女", required = true, position = 4)
    private String gender;
    
    /**
     * 出生日期
     */
    @ApiModelProperty(value = "出生日期", example = "1990-01-01", required = true, position = 5)
    private LocalDate birthDate;
    
    /**
     * 电话
     */
    @ApiModelProperty(value = "电话", example = "13800138000", required = true, position = 6)
    private String phone;
    
    /**
     * 状态
     */
    @ApiModelProperty(value = "状态", example = "在职", allowableValues = "在职,请假,休息,离职", required = true, position = 7)
    private String status;
    
    /**
     * 驾驶证号码
     */
    @ApiModelProperty(value = "驾驶证号码", example = "340123456789012", required = true, position = 8)
    private String licenseNumber;
    
    /**
     * 备注
     */
    @ApiModelProperty(value = "备注", example = "优秀驾驶员", required = false, position = 9)
    private String remark;
    
    /**
     * 创建时间
     */
    @ApiModelProperty(value = "创建时间", hidden = true)
    private LocalDateTime createTime;
    
    /**
     * 更新时间
     */
    @ApiModelProperty(value = "更新时间", hidden = true)
    private LocalDateTime updateTime;
    
    /**
     * 删除标志（0代表存在 1代表删除）
     * 注意：现在使用物理删除，此字段仅用于兼容性保留
     */
    @ApiModelProperty(hidden = true)
    @TableLogic
    private Integer delFlag;
    
    /**
     * 计算当前年龄
     * @return 根据出生日期计算的年龄
     */
    @ApiModelProperty(value = "年龄", example = "30", accessMode = ApiModelProperty.AccessMode.READ_ONLY)
    public Integer getAge() {
        if (birthDate == null) {
            return null;
        }
        return Period.between(birthDate, LocalDate.now()).getYears();
    }
} 